#!/bin/bash

server="ljs-m3400qa"
homeDir="home"
userName="ljs"

function usage() {
	echo "Usage: put_file.sh [-u <user_name> | -p <password> | -h ] <file_or_dir_to_put>"
    echo "     把指定的文件或者目录上传到${server}"
    echo "     -u <user_name>: 把<file_or_dir_to_put>放到<user_name>的Home目录下。缺省${userName}"
    echo "     -p <password>: ssh的password，缺省同<user_name>"
    echo "     -h: 输出此帮助信息"
	exit 1
}

while getopts "u:p:h" arg
do
  case "${arg}" in 
    u)
      userName="$OPTARG"
      shift 2
      ;;
    p)
      password="$OPTARG"
      shift 2
      ;;
    *)
      usage
      ;;
  esac
done

# 检查是否指定了要上载的文件或目录
if [ $# -eq 0 ]
then
  usage
fi

dst=${userName}@${server}:/${homeDir}/${userName}/tmp
echo scp -r "$@" ${dst}

if [ -z "${password}" ]
then 
    scp -r "$@" ${dst}
else
    sshpass -p ${password} scp -r "$@" ${dst}
fi
